package com.itheima.controller;

import com.itheima.domain.SmsHomeAdvertise;
import com.itheima.manager.SmsHomeAdvertiseManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SmsHomeAdvertiseController {
    @Autowired
    SmsHomeAdvertiseManager smsHomeAdvertiseManager;

    /**
     * 营销-广告-分页查询广告
     * @param endTime
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("/home/advertise/list")
    public R findAdvertiseByPage(@RequestParam(required = false) String endTime,
                                 @RequestParam(required = false) String name,
                                 @RequestParam(required = false) Integer pageNum,
                                 @RequestParam(required = false) Integer pageSize,
                                 @RequestParam(required = false) Integer type){
        return smsHomeAdvertiseManager.findAdvertiseByPage(endTime,name,pageNum,pageSize,type);
    }

    /**
     * 营销-广告-广告详情
     * @param id
     * @return
     */
    @GetMapping("/home/advertise/{id}")
    public R findAdvertiseInfo(@PathVariable Integer id){
        return smsHomeAdvertiseManager.findAdvertiseInfo(id);
    }

    /**
     * 营销-广告-修改广告
     * @param advertise
     * @param id
     * @return
     */
    @PostMapping("/home/advertise/update/{id}")
    public R updateAdvertise(@RequestBody SmsHomeAdvertise advertise,
                             @PathVariable Integer id){
        return smsHomeAdvertiseManager.updateAdvertise(advertise,id);
    }

    /**
     * 营销-广告-修改上线|下线状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/home/advertise/update/status/{id}")
    public R updateAdvertiseStatus(@PathVariable Integer id,
                                   @RequestParam Integer status){
        return smsHomeAdvertiseManager.updateAdvertiseStatus(id,status);
    }

    /**
     * 营销-新品-添加广告
     * @param advertise
     * @return
     */
    @PostMapping("/home/advertise/create")
    public R addAdvertise(@RequestBody SmsHomeAdvertise advertise){
        return smsHomeAdvertiseManager.addAdvertise(advertise);
    }

    /**
     * 营销-新品-删除广告
     * @param ids
     * @return
     */
    @PostMapping("/home/advertise/delete")
    public R deleteAdvertise(@RequestParam List<Integer> ids){
        return smsHomeAdvertiseManager.deleteAdvertise(ids);
    }
}
